<script setup lang="ts">
import {ref} from 'vue'
import { useRouter } from 'vue-router';


// 新增 props 定义
const props = defineProps<{
  activeNav: string ,
  activeSubNav: string
  // 接收父组件传递的 activeNav
}>()
const showSubNav = ref(false)
// 定义路由的跳转
const router = useRouter();
const navigateTo = (path: string) => {
  router.push(path);
};
const emit = defineEmits(['update:activeNav', 'update:activeSubNav'])
// 点击导航项时触发事件
const handleNavClick = (newNav: string,newSubNav: string, path: string) => {
  emit('update:activeNav', newNav)
  emit('update:activeSubNav', newSubNav)
  navigateTo(path)
}

</script>

<template>
  <nav class="fixed-nav">
    <div class="nav-content">
      <div class="logo">
        <img
            src="@/assets/logo/logoAndText.png"
            alt="公司LOGO"
            class="logo-image"
            @click="navigateTo('/')"
        />
      </div>
      <ul class="nav-items">
        <li
            :class="{ active: activeNav === '1' }"
            @click="handleNavClick('1', '0', '/zhiyouyun/index')"
        >首页
        </li>
        <li
            :class="{ active: activeNav === '2' }"
            @click="handleNavClick('2', '0', '/zhiyouyun/aboutMe')"
        >关于知优
        </li>
        <li
            :class="{ active: activeNav === '3' }"
            @mouseenter="showSubNav = true"
            @mouseleave="showSubNav = false"

        >
          产品服务 <span>></span>
          <ul class="sub-nav" v-show="showSubNav">
            <li @click="handleNavClick('3', '3-1', '/zhiyouyun/produceService/zyszjl')" class="subNavLi subNavLi1">知数擎</li>
            <li @click="handleNavClick('3', '3-2','/zhiyouyun/produceService/channelControl')" class="subNavLi subNavLi2">渠道管控</li>
            <li @click="handleNavClick('3', '3-3','/zhiyouyun/produceService/intellectualPropertyProtection')" class="subNavLi subNavLi3">知产保护</li>
            <li @click="handleNavClick('3', '3-4','/zhiyouyun/produceService/ownership')" class="subNavLi subNavLi4">确权布局</li>
            <li @click="handleNavClick('3', '3-5','/zhiyouyun/produceService/authorizeManage')" class="subNavLi subNavLi5">授权管理</li>
          </ul>
        </li>
<!--        <li-->
<!--            :class="{ active: activeNav === '4' }"-->
<!--            @click="handleNavClick(activeNav,activeSubNav,'/zhiyouyun/zhiyouColumn')"-->
<!--        >致优专栏-->
<!--        </li>-->
        <li
            :class="{ active: activeNav === '5' }"
            @click="handleNavClick(activeNav,activeSubNav,'/zhiyouyun/contactUs')"
        >联系我们
        </li>

      </ul>
      <a class="login-item" href="#">
        <img
            src="@/assets/login/login-icon.svg"
            class="login-icon"
            alt="登录图标"
        />
        登录
      </a>
    </div>
  </nav>
</template>

<style scoped>
/* 新增导航栏样式 */
.fixed-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 80px;
  background: rgba(16, 16, 16, 0.7);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.nav-content {
  max-width: 1920px;
  margin: 0;
  padding: 0;
  height: 100%;
  display: flex;
  align-items: center;
}


.logo {
  margin-left: 360px;
  /* 添加右边距 */
  margin-right: 40px;

}

.logo-image {
  width: 166px;
  height: 52px;
  object-fit: contain;
  margin-top: 30px;

}

.nav-items {
  display: flex;
  gap: 68px; /* 修改间距为68px */
  list-style: none;
  /* margin-left: 606px; */
}

.nav-items > li > span {
  display: inline-block;
  transform: rotate(90deg);
  font-size: 12px;
  margin-left: 4px;
  vertical-align: middle;
}

.nav-items > li {
  color: #FFFFFF;
  cursor: pointer;
  transition: color 0.3s;
  font-size: 20px;
  line-height: 28px;
  font-family: " AlibabaPuHuiTi_2_55_Regular", sans-serif;
  white-space: nowrap; /* 防止文字换行 */
  flex: 0 1 auto; /* 添加自适应宽度 */
  height: 80px;
  display: flex;
  align-items: center;
}



/* .nav-items li:hover {
  filter: brightness(0) saturate(100%) invert(45%) sepia(110%) saturate(800%) hue-rotate(0deg);
} */

.nav-items li.active,
.nav-items li:hover {
  color: #FF6600;
}

.nav-items > li:not(.login-item) {
  position: relative;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-items > li:not(.login-item)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 4px;
  background: linear-gradient(to right, #FF973A, #FF6600);
  border-radius: 3px;
  opacity: 0;
  transition: all 0.3s ease;
}

.nav-items > li.active::after,
.nav-items > li:hover::after {
  width: 100%;
  opacity: 1;
  left: 0;
  transform: none;
}

.sub-nav {
  position: absolute;
  top: 100%;
  left: -35px;
  width: 160px;
  height: 249px;
  background: rgba(0,0,0,0.32);
  border-radius: 8px;
  border: 1px solid rgba(255,102,0,0.32);
  backdrop-filter: blur(10px);
  z-index: 100;
  padding:  0;
  margin: 0;
  list-style: none;
}

.sub-nav li {

  margin-left: 12px;
  padding: 0;
  width: 136px;
  height: calc(100% / 5);
  line-height: 40px;
  color: #FFFFFF;
  cursor: pointer;
  transition: all 0.3s;

  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
/* .sub-nav .subNavLi1{
  margin-top: 5px;
} */
.sub-nav .subNavLi1,
.sub-nav .subNavLi2,
.sub-nav .subNavLi3,
.sub-nav .subNavLi4{
  border-bottom: 1px solid rgba(120, 120, 120, 0.2);
  border-radius: 0.5px 1px;
}


.nav-items li.active::after,
.nav-items li:hover::after {
  opacity: 1;
}

.login-item {
  margin-left: 236px !important;
  font-family: "libabaPuHuiTi_2_55_Regular", sans-serif;
  font-size: 20px;
  line-height: 28px;
  color: #FFFFFF;
  font-weight: normal;
  display: flex;
  align-items: center;
  height: 28px;
  text-decoration: none; /* 去除下划线 */
  outline: none; /* 去除点击时的轮廓 */
}

.login-item:hover {
  color: #FFFFFF; /* 保持悬停颜色不变 */
  text-decoration: none; /* 确保悬停时也没有下划线 */
}
.login-icon{
  margin-right: 10px;
}
</style>